fix: show in-flight expect.poll on test timeout error#10137
Draft
hi-ogawa wants to merge 1 commit intovitest-dev:mainfrom
Draft
fix: show in-flight expect.poll on test timeout error#10137hi-ogawa wants to merge 1 commit intovitest-dev:mainfrom
expect.poll on test timeout error#10137hi-ogawa wants to merge 1 commit intovitest-dev:mainfrom
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
hi-ogawa
commented
Apr 13, 2026
Comment on lines
+252
to
+269
| function recordErrorOnTimeout(createError: () => unknown) { | ||
| const addError = () => { | ||
| // as cause? | ||
| // const timeoutError = context.signal.reason as Error; | ||
| // if (!timeoutError.cause) { | ||
| // timeoutError.cause = createError() | ||
| // } | ||
|
|
||
| // or as stack? | ||
| const timeoutError = context.signal.reason as Error | ||
| if (timeoutError && timeoutError.stack) { | ||
| copyStackTrace(timeoutError, createError() as any) | ||
| } | ||
|
|
||
| // or as dedicated error? | ||
| // recordError(createError()) | ||
| } | ||
| context.signal.addEventListener('abort', addError) |
Collaborator
Author
There was a problem hiding this comment.
There are the three variants:
- as cause
FAIL test/repro.test.ts > repro
Error: Test timed out in 2000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
❯ test/repro.test.ts:3:1
1| import { expect, test } from 'vitest'
2|
3| test('repro', { timeout: 2000 }, async () => {
| ^
4| await expect.poll(async () => {
5| return 4321
Caused by: Error: expect.poll did not succeed in time.
❯ test/repro.test.ts:6:26- as stack
FAIL test/repro.test.ts > repro
Error: Test timed out in 2000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
❯ test/repro.test.ts:6:26
4| await expect.poll(async () => {
5| return 4321
6| }, { timeout: 10000 }).toBe(1234)
| ^
7| })
8|- as a separate error
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL test/repro.test.ts > repro
Error: expect.poll did not succeed in time.
❯ test/repro.test.ts:6:26
4| await expect.poll(async () => {
5| return 4321
6| }, { timeout: 10000 }).toBe(1234)
| ^
7| })
8|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
FAIL test/repro.test.ts > repro
Error: Test timed out in 2000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
❯ test/repro.test.ts:3:1
1| import { expect, test } from 'vitest'
2|
3| test('repro', { timeout: 2000 }, async () => {
| ^
4| await expect.poll(async () => {
5| return 4321
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
expect.pollon test timeout error #10136I found a case where I want to surface what's pending on test timeout and this is possible by hooking in to
context.signal. My scenario wasn't actuallyexpect.pollbut something similar to our test-util'swaitForOutput.This PR adds such helper-ish method as
context.recordErrorOnTimeoutand also this can be used for surfacing in-flightexpect.poll, which I think can be useful too.What's convenient about
context.recordErrorOnTimeoutis that it allows custom async assertion to not need to estimate and hard-code right own timeout to be triggered before test timeout.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.